<?php
/**
 * Created by PhpStorm.
 * User: Me
 * Date: 2018/10/10
 * Time: 12:49
 */

namespace app\common\utils;


class BackNotify
{
   private static function curl_to_websocket_server($option){
        $url=WEBSOCKET_URL;


        //使用 get 传递 json 字符串需 对 json字符串 使用urlencode编码
        $json_str= json_encode($option);
        $access_url=$url."?auth=0e541bf02aab56ce6e7e8c3dfae7f77a&params=".urlencode($json_str);


        $ch =curl_init($access_url);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        //如果时间小于1000毫秒也就是1秒的话,会立马报错
        //增加 curl_setopt($ch, CURLOPT_NOSIGNAL, 1) 可以解决此问题
        curl_setopt($ch,CURLOPT_TIMEOUT_MS,200);
        curl_setopt($ch,CURLOPT_NOSIGNAL,1);

        curl_exec($ch);

        curl_close($ch);
    }
    public static function addNotifyNum($option)
    {

        $option['op']='add';
        if(!isset($option['notify_num']))
        {
            $option['notify_num']=1;
        }

        self::curl_to_websocket_server($option);
    }
    public static function descNotifyNum($option)
    {
        $option['op']='sub';

        if(!isset($option['notify_num']))
        {
            $option['notify_num']=1;
        }

        self::curl_to_websocket_server($option);
    }
}